﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleJson;

namespace Dropbox
{
    public partial class DropboxAccountInfo
    {
        private DropboxAccountInfo() { }
        public static DropboxAccountInfo Load(string json)
        {
            var result = new DropboxAccountInfo
            {
                QuotaInfo = new DropBoxQuotaInfo()
            };

            JsonObject jsonObj;
            try
            {

                jsonObj = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(json);
            }
            catch (Exception ex)
            {
                return result;
            }
            
            if (jsonObj.ContainsKey("referral_link"))
            {
                result.ReferralLink = jsonObj["referral_link"].ToString();
            }
            if (jsonObj.ContainsKey("display_name"))
            {
                result.DisplayName = jsonObj["display_name"].ToString();
            }
            if (jsonObj.ContainsKey("uid"))
            {
                result.UserID = jsonObj["uid"].ToString();
            }
            if (jsonObj.ContainsKey("country"))
            {
                result.Country = jsonObj["country"].ToString();
            }
            if (jsonObj.ContainsKey("quota_info"))
            {
                result.QuotaInfo = DropBoxQuotaInfo.Load(jsonObj["quota_info"].ToString());
            }
            
            return result;

        }

        public string ReferralLink { get; private set; }
        public string DisplayName { get; private set; }
        public string UserID { get; private set; }
        public string Country { get; private set; }
        public DropBoxQuotaInfo QuotaInfo { get; private set; }
    }
}
